php () {
    create_network
    # 配置PHP与nginx互通
    cp -r ./nginx ${VOLUME}
    # 生成自签证书
    openssl req -newkey rsa:2048 -nodes -keyout rsa_private.key -x509 -days 365 -out cert.crt -subj "/C=CN/ST=GD/L=SZ/O=fast/OU=dev/CN=fast.cn/emailAddress=fast@fast.cn"

    if [ -f './cert.crt' ]; then
        mv ./cert.crt ${VOLUME}/nginx/conf.d
        mv ./rsa_private.key ${VOLUME}/nginx/conf.d
    fi
    # 创建nginx服务器
    DOCKER_CMD="docker run -d --network denet --ip 10.2.2.2 \
        -p 80:80 \
        -p 443:443 \
        -p 9000:9000 \
        --name php \
        -w /usr/share/nginx/html \
        -v ${VOLUME}/www:/usr/share/nginx/html \
        -v ${VOLUME}/nginx/conf.d:/usr/share/nginx/conf/conf.d \
        -v ${VOLUME}/nginx/nginx.conf:/usr/share/nginx/conf/nginx.conf \
        -v ${VOLUME}/logs/nginx:/usr/share/nginx/logs \
        --restart always \
        decezz/php:7.4-fpm-alpine"
    docker_exec $DOCKER_CMD
}

ssh () {
    # ssh tag=(latest, ubuntu, alpine)
    DOCKER_CMD="docker run -d \
        -p 2222:2222 \
        -p 8686:8686 \
        --name ssh \
        --restart always \
        decezz/ssh:latest"
    docker_exec $DOCKER_CMD
}

v2ray () {
    DOCKER_CMD="docker run -d \
        -p 10808-10810:10808-10810 \
        --name v2ray \
        --restart always \
        decezz/v2ray$( tag )"
    docker_exec $DOCKER_CMD
}

smartdns () {
    DOCKER_CMD="docker run -d \
        -p 53:53/tcp \
        -p 53:53/udp \
        --name smartdns \
        --restart always \
        decezz/smartdns:latest"
    docker_exec $DOCKER_CMD
}
